//
//  ZZProductDetailViewController.m
//  ZuZuBao
//
//  Created by Felix on 2024/4/18.
//

#import "ZZProductDetailViewController.h"
#import "ZZProductDetailTableViewCell.h"
#import "ZZConfirmOrderViewController.h"

@interface ZZProductDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) ZZProductDetailTableViewCell * detailCell;
@property (nonatomic, strong) UIButton * rentButton;

@end

@implementation ZZProductDetailViewController
{
    UITableView *tableView;
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"商品详情";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createView];
}

- (void)createView {
    tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarHeight, kScreenWidth, kScreenHeight - kNavBarHeight - kSafeBottomHeight - 58) style:UITableViewStylePlain];
    tableView.backgroundColor = [UIColor clearColor];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    [tableView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    
    self.detailCell = [[ZZProductDetailTableViewCell alloc] init];
    
    self.rentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.rentButton.frame = CGRectMake(kPadding, kScreenHeight - kSafeBottomHeight - 8 - 42, kScreenWidth - kPadding * 2, 42);
    self.rentButton.layer.cornerRadius = 21;
    self.rentButton.layer.masksToBounds = YES;
    self.rentButton.backgroundColor = [UIColor blackColor];
    [self.rentButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rentButton setTitle:@"租用" forState:UIControlStateNormal];
    self.rentButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    [self.rentButton addTarget:self action:@selector(rentAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.rentButton];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // 返回你想要的行数
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 300;
}
  
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self.detailCell setCellData:self.model];
    return self.detailCell;
}

- (void)rentAction {
    ZZConfirmOrderViewController * vc = [[ZZConfirmOrderViewController alloc] init];
    vc.model = self.model;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
